<?php

class Services_Config_Boot implements IService{

    private $_handler = null;
    
    public function __construct($driver){
        if(is_null($this->_handler)){
            $driverPath = dirname(__FILE__).DS.'driver'.DS.$driver.'.php';
            if(is_file($driverPath)) include($driverPath);
            else throw new MHttpException("Driver {$driver} cannot found in Service config");
            $driverClass = 'config_driver_'.$driver;
            $this->_handler = new $driverClass;
        }
    }

    public function C($name=null,$value=null){
        // 无参数时获取所有
        if(empty($name)) return $this->_handler->all();
        // 优先执行设置获取或赋值
        if (is_string($name))
        {
            $name = strtolower($name);
            if (is_null($value))
                return $this->_handler->get($name);
            $this->_handler->set($name,$value);
            return;
        }
        // 批量设置
        if(is_array($name)){
            $this->_handler->merge($name);
            return $this->_handler->all();
        }
        return null;//避免非法参数
    }
}